package businesslogic;

import java.util.ArrayList;

import org.omg.CORBA.OMGVMCID;

import databaseservice.BookPOService;
import databaseservice.MemberPOService;

import po.BookPO;
import po.MemberPO;
import businesslogic.network.RMIStubClient;
import businesslogicservice.CollectBookBLService;

public class CollectBookBLService_Stub implements CollectBookBLService {
	private MemberPOService mMemberPOService;
	private BookPOService mBookPOService;
	public CollectBookBLService_Stub(RMIStubClient client){
		mMemberPOService=client.memberPOService;
		mBookPOService=client.bookPOService;
	}

	@Override
	public boolean addAnCollect(int memberID, int bookID) {
		// TODO Auto-generated method stub
		try {
			return mMemberPOService.addAnCollect(memberID, bookID);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	public boolean cancelAnCollect(int memberID, int bookID) {
		// TODO Auto-generated method stub
		try {
			return mMemberPOService.deleteAnCollect(memberID, bookID);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	public ArrayList<BookPO> checkCollect(int memberID) {
		// TODO Auto-generated method stub
		try {
			MemberPO m=mMemberPOService.search(memberID);
			ArrayList<Integer> collections=m.getCollections();
			ArrayList<BookPO> books=new ArrayList<BookPO>();
			for(int bookID:collections){
				BookPO b=mBookPOService.searchABook(bookID);
				books.add(b);
			}
			return books;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

}
